package club.vann.kafka.mock.common.model.csv;

import club.vann.kafka.mock.util.CsvUtil;
import java.util.ArrayList;
import java.util.List;

/** 预警任务CSV格式信息 */
public abstract class AbstractCsv {
  /** 将数据转换为CSV格式 */
  protected static <T> CsvTable convert(List<String> headerList, List<T> list) {
    CsvTable csvTable = new CsvTable();
    csvTable.setHeaderList(headerList);
    List<List<String>> rowDataList = new ArrayList<>();
    if (list == null || list.isEmpty()) {
      return csvTable;
    }
    list.forEach(
        t -> {
          List<String> rowData = CsvUtil.parseWithHeader(headerList, t);
          rowDataList.add(rowData);
        });
    csvTable.setDataList(rowDataList);
    return csvTable;
  }
}
